package com.jtny.nytb.equipment.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.jtny.component.entity.WebResponse;
import com.jtny.nytb.equipment.service.UserEquipmentRelationService;
import com.jtny.nytb.equipment.vo.device.EquipmentInfoVO;
import com.jtny.nytb.equipment.vo.device.UserEquipmentQueryVO;
import com.jtny.nytb.powermonitor.service.PowerMonitorIterationService;
import com.jtny.nytb.powermonitor.vo.EquipmentVO;
import com.jtny.nytb.powermonitor.vo.MonitorItemVO;
import com.jtny.nytb.powermonitor.vo.PowerMonitorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 智慧能源中心 - 车智斌
 * @package com.jtny.nytb.energymonitor.equipment.controller
 * @fileName UserEquipmentRelationController.java
 * @createTime 2024年03月19日 09:42
 * @Copyright© 2024 jtny
 * 江投能源技术研究院 版权所有
 */
@RestController
@Api(value = "用户设备关联", tags = "用户设备关联")
@ApiSort(204006)
@RequestMapping("/user-equipment-relation")
@AllArgsConstructor
public class UserEquipmentRelationController {
    @Autowired
    private PowerMonitorIterationService powerMonitorIterationService;

    @Autowired
    private UserEquipmentRelationService userEquipmentRelationService;

    @ApiOperation("查询区域层级信息")
    @ApiOperationSupport(order = 1)
    @PostMapping("/queryAreaInfo")
    @ResponseBody
    public WebResponse<?> queryAreaInfo() {

        MonitorItemVO monitorItemVO = powerMonitorIterationService.queryAll();

        return WebResponse.success("操作成功", monitorItemVO);
    }

    @ApiOperation("根据区域层级信息查询设备信息")
    @ApiImplicitParam(name = "powerMonitorVO", value = "区域配电监测信息VO对象", required = true, paramType = "query", dataType = "PowerMonitorVO")
    @ApiOperationSupport(order = 2)
    @PostMapping("/queryEquipmentsByArea")
    @ResponseBody
    public WebResponse<?> queryEquipmentsByArea(@RequestBody PowerMonitorVO powerMonitorVO) {

        List<EquipmentVO> equipmentVOS = powerMonitorIterationService.queryEquipments(powerMonitorVO);

        return WebResponse.success("操作成功", equipmentVOS);
    }

    @ApiOperation("根据区域层级信息查询设备信息")
    @ApiImplicitParam(name = "powerMonitorVO", value = "区域配电监测信息VO对象", required = true, paramType = "query", dataType = "PowerMonitorVO")
    @ApiOperationSupport(order = 2)
    @PostMapping("/queryEqByAreaForInsu")
    @ResponseBody
    public WebResponse<?> queryEqByAreaForInsu(@RequestBody PowerMonitorVO powerMonitorVO) {

        List<EquipmentVO> equipmentVOS = powerMonitorIterationService.queryEqByAreaForInsu(powerMonitorVO);

        return WebResponse.success("操作成功", equipmentVOS);
    }


    @ApiOperation("根据用户code查询绑定的设备信息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/queryEquipmentsByUser")
    @ResponseBody
    public WebResponse<?> queryEquipmentsByUser(@RequestBody UserEquipmentQueryVO userEquipmentQueryVO) {

        List<EquipmentInfoVO> equipmentVOS = userEquipmentRelationService.queryEquipmentsByUser(userEquipmentQueryVO);

        return WebResponse.success("操作成功", equipmentVOS);
    }

    @ApiOperation("保存用户设备关联关系")
    @ApiImplicitParam(name = "equipmentIds", value = "设备id集合", required = true, paramType = "query", dataType = "List<String>")
    @ApiOperationSupport(order = 4)
    @PostMapping("/insertUserEquipmentRelation")
    @ResponseBody
    public WebResponse<?> insertUserEquipmentRelation(@RequestBody UserEquipmentQueryVO userEquipmentQueryVO) {

        userEquipmentRelationService.insertUserEquipmentRelation(userEquipmentQueryVO);

        return WebResponse.success("操作成功");
    }

    @ApiOperation("删除用户设备关联关系")
    @ApiImplicitParam(name = "equipmentIds", value = "设备id集合", required = true, paramType = "query", dataType = "List<String>")
    @ApiOperationSupport(order = 5)
    @PostMapping("/deleteUserEquipmentRelation")
    @ResponseBody
    public WebResponse<?> deleteUserEquipmentRelation(@RequestBody UserEquipmentQueryVO userEquipmentQueryVO) {

        userEquipmentRelationService.deleteUserEquipmentRelation(userEquipmentQueryVO);

        return WebResponse.success("操作成功");
    }
}
